package com.xz.xzutils.settings.mybatislogplus;

import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.util.NlsContexts;
import com.xz.xzutils.settings.gui.MybatisLogPlusSettings;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;

/**
 * @author DONG.WANG17@HAND-CHINA.COM
 * @since 2025/3/1-03-01 19:21
 */
public class MybatisLogPlusSettingsConfig implements Configurable {
    private final MybatisLogPlusPersistentState stateService = MybatisLogPlusPersistentState.getInstance();
    private final MybatisLogPlusSettings settingsUI = new MybatisLogPlusSettings();

    @Override
    public @NlsContexts.ConfigurableName String getDisplayName() {
        return "XzUtils";
    }

    @Override
    public @Nullable JComponent createComponent() {
        return settingsUI.getRootComponent();
    }

    @Override
    public boolean isModified() {
        return !settingsUI.getUiState().equals(stateService.getState());
    }

    @Override
    public void apply() {
        stateService.loadState(settingsUI.getUiState());
    }

    @Override
    public void reset() {
        settingsUI.renderUI(stateService.getState());
    }
}
